<template>
  <el-form :model="detailForm" ref="detailForm" :rules="rules"
           :label-position="labelPosition" :class="isEdit?'':'formItem'">
    <el-card class="box-card" shadow="never">
      <div slot="header" class="header-card">
        <span class="header-card-title">资金部反馈</span>
      </div>

      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="是否支付至车管:" prop="isPay">
            <el-select v-model="detailForm.isPay" v-if="isEdit" @change="handleSelect"
                       placeholder="请选择是否支付至车管" style="width: 100%;">
              <el-option v-for="v in dict.type.ispay_vehicle" :label="v.label" :key="v.value" :value="Number(v.value)">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="付款类型:" prop="payType">
            <el-select v-model="detailForm.payType" v-if="isEdit" placeholder="请选择付款类型" style="width: 100%;">
              <el-option v-for="v in dict.type.purchase_payment_type" :label="v.label" :key="v.value"
                         :value="Number(v.value)">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

    </el-card>
  </el-form>
</template>

<script>
import processingAnnual from "@/views/cwgd/components/annualInspection/processingAnnual.vue";

export default {
  name: 'fundFeedback',
  dicts: ['purchase_payment_type', 'ispay_vehicle'],
  components: {processingAnnual},
  model: {
    prop: 'detailForm',
    event: 'update:detailForm',
  },

  props: {
    detailForm: {
      type: Object,
      default: {},
    },
    state: {
      type: String,
      default: "",
    }
  },
  data() {
    return {
      rules: {
        isPay: [{required: this.state === 'write', message: '请选择是否支付至车管', trigger: 'change'}],
        payType: [{required: this.state === 'write', message: '请选择付款类型', trigger: 'change'}]
      },


    };
  },
  computed: {
    labelPosition() {
      if (this.isEdit) {
        return "top";
      } else {
        return "left";
      }
    },
    isEdit() {
      let bool;
      switch (this.state) {
        case "write":
          bool = true;
          break;
        case "disabled":
          bool = false;
          break;
        case "readonly":
          bool = false;
          break;
      }
      return bool
    },
  },
  watch: {
    detailForm: {
      handler(newVal, oldVal) {
      },
      immediate: true,
      deep: true
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    handleSelect(val) {
      this.detailForm.isPay = val
      if (Number(val) === 1) {
        this.detailForm.payType = 2
      }
      if (Number(val) === 2) {
        this.detailForm.payType = 1
      }


    },
    handleEffect() {
      return new Promise((resolve, reject) => {
        this.$refs.detailForm.validate((valid) => {
          if (valid) {
            resolve()
          } else {
            reject()
          }
        });
      })
    },
    valid() {
      return new Promise((resolve) => {
        this.$refs.detailForm.validate((valid) => {
          resolve(valid);
        });
      })
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/styles/cwgd/formScss.scss";
</style>


